{template 'common/header-gw'}
<ol class="breadcrumb">
	<li><a href="./?refresh"><i class="fa fa-home"></i></a></li>
	<li class=""><a href="{url 'system/welcome'}">系统</a></li>
	<li class="active">一键更新</li>
</ol>
<ul class="nav nav-tabs">
	<li{if $do == 'upgrade'} class="active"{/if}><a href="{php echo url('cloud/upgrade');}">自动更新</a></li>
	{if $do == 'shipping'}<li class="active"><a href="javscript:;">升级处理</a></li>{/if}
</ul>
<div class="clearfix">
	<div id="tips" style="display:block; overflow:hidden;">
		<style>
		.refresh-log ul{margin:10px 0 0 0;}
		.refresh-log ul em{font-style:normal; float:right;}
		</style>
		<div class="row">
			<div class="col-lg-6">
				<div class="alert alert-info refresh-log">
					<h4><i class="fa fa-refresh"></i> 更新日志</h4>
					<ul class="list-unstyled">
					<script type="text/javascript" src="http://bbs.we7.cc/api.php?mod=js&bid=17"></script>
					</ul>
				</div>
			</div>
			<div class="col-lg-6">
				<div class="alert alert-info refresh-log">
					<h4><i class="fa fa-bullhorn"></i> 系统公告</h4>
					<ul class="list-unstyled">
					<script type="text/javascript" src="http://bbs.we7.cc/api.php?mod=js&bid=20"></script>
					</ul>
				</div>
			</div>
		</div>
	</div>

	<div class="alert alert-danger">
		<i class="fa fa-exclamation-triangle"></i> 更新时请注意备份网站数据和相关数据库文件！官方不强制要求用户跟随官方意愿进行更新尝试！
	</div>
	<form action="" method="post" class="form-horizontal" role="form">
		{if !empty($upgrade) && !empty($upgrade['upgrade'])}
		<div class="form-group">
			<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">版本</label>
			<div class="col-sm-10">
				<p class="form-control-static"><span class="fa fa-square-o"></span> &nbsp; 系统当前版本: v{php echo IMS_VERSION}</p>
				{if $upgrade['version'] != IMS_VERSION}
				<p class="form-control-static"><span class="fa fa-square-o"></span> &nbsp; 存在的新版本: v{$upgrade['version']}</p>
				{/if}
				<div class="help-block">在一个发布版中可能存在多次补丁, 因此版本可能未更新</div>
			</div>
		</div>
		<div class="form-group">
			<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">发布日期</label>
			<div class="col-sm-10">
				<p class="form-control-static"><span class="fa fa-square-o"></span> &nbsp; 系统当前Release版本: Build {php echo IMS_RELEASE_DATE}</p>
				{if $upgrade['release'] != IMS_RELEASE_DATE}
				<p class="form-control-static"><span class="fa fa-square-o"></span> &nbsp; 存在的新Release版本: Build {$upgrade['release']}</p>
				{/if}
				<div class="help-block">系统会检测当前程序文件的变动, 如果被病毒或木马非法篡改, 会自动警报并提示恢复至默认版本, 因此可能修订日期未更新而文件有变动</div>
			</div>
		</div>
		{if !empty($upgrade['message'])}
		<div class="form-group">
			<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">注意事项</label>
			<div class="col-sm-10">
				<div class="alert alert-danger">
					{$upgrade['message']}
				</div>
			</div>
		</div>
		{/if}
		{if !empty($upgrade['scripts'])}
		<div class="form-group">
			<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">更新通告</label>
			<div class="col-sm-10">
				{loop $upgrade['scripts'] $ver}
				<p class="form-control-static">({$upgrade['family']}{$ver['version']} Build {$ver['release']}) - {$ver['message']}</p>
				{/loop}
			</div>
		</div>
		{/if}
		{if !empty($upgrade['database'])}
		<div class="form-group">
			<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">数据库同步情况</label>
			<div class="col-sm-10">
				<div class="help-block"><strong>注意: 重要: 本次更新涉及到数据库变动, 请做好备份.</strong></div>
				<div class="alert alert-success" style="line-height:20px;margin-top:20px;">
					{loop $upgrade['database'] $line}
					<div class="row">
						<div class="col-xs-2 col-lg-1">表名:</div>
						<div class="col-xs-2 col-lg-2">{$line['tablename']}</div>
						{if !empty($line['new'])}
						<div class="col-xs-8 col-lg-9">New</div>
						{else}
						<div class="col-xs-8 col-lg-9">{if !empty($line['fields'])}fields: {$line['fields']}; {/if}{if !empty($line['indexes'])}indexes: {$line['indexes']}{/if}</div>
						{/if}
					</div>
					{/loop}
				</div>
			</div>
		</div>
		{/if}
		{if !empty($upgrade['files'])}
		<div class="form-group">
			<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">文件同步情况</label>
			<div class="col-sm-10">
				<div class="help-block"><strong>注意: 重要: 本次更新涉及到程序变动, 请做好备份.</strong></div>
				<div class="alert alert-info" style="line-height:20px;margin-top:20px;">
					{loop $upgrade['files'] $line}
					<div><span style="display:inline-block; width:30px;">{if is_file(IA_ROOT . $line)}M{else}A{/if}</span>{$line}</div>
					{/loop}
				</div>
			</div>
		</div>
		{/if}
		<div class="form-group">
			<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">更新协议</label>
			<div class="col-sm-10">
				<div class="checkbox">
					<label>
						<input type="checkbox" id="agreement_0"> 我已经做好了相关文件的备份工作
					</label>
				</div>
				<div class="checkbox">
					<label>
						<input type="checkbox" id="agreement_1"> 认同官方的更新行为并自愿承担更新所存在的风险
					</label>
				</div>
				<div class="checkbox">
					<label>
						<input type="checkbox" id="agreement_2"> 理解官方的辛勤劳动并报以感恩的心态点击更新按钮
					</label>
				</div>
				<div class="checkbox">
					<label>
						<input type="checkbox" id="agreement_3"> 认同“购买微擎商业授权后进行商业化运营”的协议
					</label>
				</div>
			</div>
		</div>
		<div class="form-group">
			<div class="col-sm-offset-2 col-md-offset-2 col-lg-offset-1 col-xs-12 col-sm-10 col-md-10 col-lg-11">
				<input type="button" id="forward" value="立即更新" class="btn btn-primary" />
				<input name="rollback" type="button" value="更新回滚列表" class="btn btn-success" data-toggle="modal" data-target="#rollback-panel" />
			</div>
		</div>
		{else}
		<div class="form-group">
			<div class="col-sm-offset-2 col-md-offset-2 col-lg-offset-1 col-xs-12 col-sm-10 col-md-10 col-lg-11">
				<input name="submit" type="submit" value="立即检查新版本" class="btn btn-primary" />
				<input name="rollback" type="button" value="更新回滚列表" class="btn btn-success" data-toggle="modal" data-target="#rollback-panel" />
				<input type="hidden" name="token" value="{$_W['token']}" />
				<div class="help-block">当前系统未检测到有新版本, 你可以点击此按钮, 来立即检查一次.</div>
			</div>
		</div>
		{/if}
	</form>
</div>
<div class="modal fade" id="rollback-panel" tabindex="-1" role="dialog" aria-labelledby="rollback-label">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<h4 class="modal-title">更新回滚列表</h4>
			</div>
			<div class="modal-body">
				<div class="alert alert-danger">
					如果要恢复更早的记录请直接查看 <b>/data/patch/</b> 目录
				</div>
				<div class="alert alert-success">
					恢复时，请手动将此目录中的文件上传至网站即可（选中全部文件和目录直接上传）
				</div>
				{if !empty($patchs)}
				<table class="table">
					<tr>
						<th style="width: 200px">日期</th>
						<th >路径</th>
					</tr>
					{loop $patchs $path}
					<tr>
						<td>{php echo date('Y-m-d')} {php echo substr($path, 0, 2)}:{php echo substr($path, 2, 2)}</td>
						<td>{$path}</td>
					</tr>
					{/loop}
				</table>
				{else}
				今天暂无更新
				{/if}
			</div>
		</div>
	</div>
</div>
{if !empty($upgrade) && !empty($upgrade['upgrade'])}
<script type="text/javascript">
	$('#forward').click(function(){
		var a = $("#agreement_0").is(':checked');
		var b = $("#agreement_1").is(':checked');
		var c = $("#agreement_2").is(':checked');
		var d = $("#agreement_3").is(':checked');
		if(a && b && c && d) {
			if(confirm('更新将直接覆盖本地文件, 请注意备份文件和数据. \n\n**另注意** 更新过程中不要关闭此浏览器窗口.')) {
				location.href = '{url "cloud/process"}';
			}
		} else {
			util.message("抱歉，更新前请仔细阅读更新协议！", '', 'error');
			return false;
		}
	});
</script>
{/if}
{template 'common/footer-gw'}
